<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link media="all" rel="stylesheet" th:href="@{../../lib/layui/css/layui.css}">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script th:src="@{../../js/jquery-3.5.1.min.js}"></script>
    <script charset="utf-8" th:src="@{../../lib/layui/layui.js}"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的-->
    <style>
        body {
            background-image: url(../../images/dinebuild.png);
            background-repeat: no-repeat;
            background-position: center;
            background-size: 100% auto;
            filter: alpha(opacity=100);
            -moz-opacity: 1;
            opacity: 1;
        }

        .vintage4{
            color: gold;
            letter-spacing: 0;
            text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135
        }

        body .add {
            border: 1px solid yellowgreen;
            border-radius: 10px;
        }

        body .add .layui-layer-title {
            background: #126d3b;
            color: #fff;
            border: none;
        }

        body .edit {
            border: 1px solid yellowgreen;
            border-radius: 10px;
        }

        body .edit .layui-layer-title {
            background: #866129;
            color: #fff;
            border: none;
        }

        body .query {
            border: 1px solid yellowgreen;
            border-radius: 10px;
        }

        body .query .layui-layer-title {
            background: #257e7b;
            color: #fff;
            border: none;
        }
    </style>
</head>
<body>
<div>
    <h1 th:class="vintage4" th:align="center">食堂楼宇后勤基础信息台账(2020年4月更新)</h1>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script id="toolbarDemo" type="text/html">
    <div class="layui-btn-container">
        <div>
            <button class="layui-btn layui-btn-danger" lay-event="delDbbis">批量删除</button>
            <button class="layui-btn layui-btn-sm" lay-event="addOne">新增</button>
            <button type="button" class="layui-btn layui-btn-normal" id="uploadExcel"><i
                    class="layui-icon"></i>数据导入
            </button>
        </div>
    </div>
</script>

<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-primary" lay-event="query">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table', "upload"], function () {
        var table = layui.table,
            $ = layui.jquery,
            layer = layui.layer,
            upload = layui.upload;

        table.render({
            elem: '#test'
            , url: '/dbbi_eat/getList'
            , totalRow: true
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , done: function (res, curr, count) {
                $("table").css("width", "100%");

            }
            , title: '用户数据表'
            , cols: [
                [
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'id', title: '楼宇编号', fixed: 'left', sort: true, totalRowText: '合计', width: 125}
                    , {field: 'location', title: '校区'}
                    , {field: 'dineBuild', title: '食堂楼宇'}
                    , {field: 'area', title: '面积', totalRow: true, sort: true}
                    , {field: 'buildTime', title: '建设时间'}
                    , {field: 'useTime', title: '投用时间',}
                    , {field: 'buildStru', title: '房屋结构'}
                    , {field: 'roofArea', title: '屋面面积', totalRow: true, sort: true}
                    , {field: 'facadeMaterial', title: '外立面材质'}
                    , {field: 'seatNum', title: '座椅数', totalRow: true, sort: true}
                    , {field: 'switchBoxNum', title: '配电箱', totalRow: true, sort: true}
                    , {field: 'fireHydrantNum', title: '消防栓', totalRow: true, sort: true}
                    , {field: 'elevatorNum', title: '电梯', totalRow: true, sort: true}
                    , {field: 'toiletNum', title: '卫生间', totalRow: true, sort: true}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 180}
                ]
            ]
            , page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            console.log(data);
            if (obj.event === 'delPbbis') {
                layer.confirm('真的删除多行吗？这可能存在风险', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "/pbbi_eat/delPbbis",
                        data: {
                            pbbiList: JSON.stringify(data)
                        },
                        type: "Post",
                        success: function (data) {
                            console.log(data);
                            if (data.code === 0) {
                                layer.msg(data.msg, {icon: 1, time: 1500, shade: 0.4}, function () {
                                    window.location.href = "/pbbi/pbbi_list";
                                });
                            } else {
                                layer.msg(data.msg, {icon: 2, time: 1500, shade: 0.4});
                            }
                        }
                    });
                });
            } else if (obj.event === 'addOne') {
                layer.msg("正在跳转新增页面，请稍等...", {icon: 6, time: 1000, shade: 0.4}, function () {
                    layer.open({
                        type: 2,
                        title: '新增数据',
                        area: ['600px', '75%'],
                        shade: [0.5],
                        content: 'dbbi_add_eat.html',
                        loading: true,
                        closeBtn: 1,
                        skin: 'add',
                        end: function () {
                            window.location.reload();
                        }
                    });
                });
            }
        });
        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            console.log(obj);
            // console.log(data);
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "/dbbi_eat/delOne",
                        data: {
                            pubBuildBaseInfo: JSON.stringify(data)
                        },
                        type: "Post",
                        success: function (data) {
                            console.log(data);
                            if (data.code === 0) {
                                layer.msg(data.msg, {icon: 1, time: 1500, shade: 0.4}, function () {
                                    window.location.href = "/pbbi/pbbi_list";
                                });
                            } else {
                                layer.msg(data.msg, {icon: 2, time: 1500, shade: 0.4});
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                var data = obj.data;
                console.log(data);
                layer.msg("正在跳转编辑页面，请稍等...", {icon: 6, time: 1000, shade: 0.4}, function () {
                    layer.open({
                        type: 2,
                        title: '编辑数据',
                        area: ['600px', '75%'],
                        shade: [0.5],
                        content: 'dbbi_edit_eat.html',
                        loading: true,
                        closeBtn: 1,
                        skin: 'edit',

                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);  // 获取子窗口中的body标签

                            body.find("#id").val(data.id);
                            body.find("#location").val(data.location);
                            body.find("#pubBuild").val(data.pubBuild);
                            body.find("#area").val(data.area);
                            body.find("#buildTime").val(data.buildTime);
                            body.find("#useTime").val(data.useTime);
                            body.find("#buildStru").val(data.buildStru);
                            body.find("#roofArea").val(data.roofArea);
                            body.find("#facadeMaterial").val(data.facadeMaterial);
                            body.find("#officeNum").val(data.officeNum);
                            body.find("#classNum").val(data.classNum);
                            body.find("#labNum").val(data.labNum);
                            body.find("#designNum").val(data.designNum);
                            body.find("#teaRestNum").val(data.teaRestNum);
                            body.find("#mulMediaNum").val(data.mulMediaNum);
                            body.find("#standardExamNum").val(data.standardExamNum);
                            body.find("#seatNum").val(data.seatNum);
                            body.find("#toiletNum").val(data.toiletNum);
                            body.find("#faucetNum").val(data.faucetNum);
                            body.find("#inductorNum").val(data.inductorNum);
                            body.find("#flashNum").val(data.flashNum);
                            body.find("#lightNum").val(data.lightNum);
                            body.find("#waterNum").val(data.waterNum);
                            body.find("#switchBoxNum").val(data.switchBoxNum);
                            body.find("#switchRoomNum").val(data.switchRoomNum);
                            body.find("#fireDoorNum").val(data.fireDoorNum);
                            body.find("#fireHydrantNum").val(data.fireHydrantNum);
                            body.find("#heatWellNum").val(data.heatWellNum);
                            body.find("#elevatorNum").val(data.elevatorNum);
                        },
                        end: function () {
                            window.location.reload();
                        }
                    });
                });
            } else {
                layer.msg("正在跳转查看页面，请稍等...", {icon: 6, time: 1000, shade: 0.4}, function () {
                    layer.open({
                        type: 2,
                        title: '查看数据',
                        area: ['600px', '75%'],
                        shade: [0.5],
                        content: 'dbbi_query_eat.html',
                        loading: true,
                        closeBtn: 1,
                        skin: 'query',

                        success: function (layero, index) {
                            var body = layer.getChildFrame('body', index);  // 获取子窗口中的body标签

                            body.find("#id").val(data.id);
                            body.find("#location").val(data.location);
                            body.find("#pubBuild").val(data.pubBuild);
                            body.find("#area").val(data.area);
                            body.find("#buildTime").val(data.buildTime);
                            body.find("#useTime").val(data.useTime);
                            body.find("#buildStru").val(data.buildStru);
                            body.find("#roofArea").val(data.roofArea);
                            body.find("#facadeMaterial").val(data.facadeMaterial);
                            body.find("#officeNum").val(data.officeNum);
                            body.find("#classNum").val(data.classNum);
                            body.find("#labNum").val(data.labNum);
                            body.find("#designNum").val(data.designNum);
                            body.find("#teaRestNum").val(data.teaRestNum);
                            body.find("#mulMediaNum").val(data.mulMediaNum);
                            body.find("#standardExamNum").val(data.standardExamNum);
                            body.find("#seatNum").val(data.seatNum);
                            body.find("#toiletNum").val(data.toiletNum);
                            body.find("#faucetNum").val(data.faucetNum);
                            body.find("#inductorNum").val(data.inductorNum);
                            body.find("#flashNum").val(data.flashNum);
                            body.find("#lightNum").val(data.lightNum);
                            body.find("#waterNum").val(data.waterNum);
                            body.find("#switchBoxNum").val(data.switchBoxNum);
                            body.find("#switchRoomNum").val(data.switchRoomNum);
                            body.find("#fireDoorNum").val(data.fireDoorNum);
                            body.find("#fireHydrantNum").val(data.fireHydrantNum);
                            body.find("#heatWellNum").val(data.heatWellNum);
                            body.find("#elevatorNum").val(data.elevatorNum);
                        }
                    });
                });
            }
        });

        upload.render({
            elem: '#uploadExcel'
            , url: '/dbbi_eat/upload'
            , type: 'post'
            , accept: 'file'
            , exts: 'xls|csv|xlsx'
            , done: function (data) {
                console.log(data);
                if (data.code === 0) {
                    layer.msg(data.msg, {icon: 1, time: 1500, shade: 0.4}, function () {
                        window.location.href = "/dbbi_eat/dbbi_list_eat";
                    });
                } else if (data.code === 1) {
                    layer.msg(data.msg, {icon: 2, time: 1500, shade: 0.4});
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1500, shade: 0.4});
                }
            }
        });
    })
</script>
</body>
</html>